﻿using System;
using System.Collections.Generic;
using System.Text;
using PostSharp.Aspects.Dependencies;

namespace Arcana.Contract.Argument.Is
{
    /// <summary>
    /// Provides a contract that adheres to <b>Argument Is Null</b> semantic.
    /// </summary>
    [Serializable]
    [AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, Roles.Conditional)]
    [ProvideAspectRole(Roles.Contract)]
    [ProvideAspectRole(Roles.Method)]
    [ProvideAspectRole(Roles.Argument)]
    [ProvideAspectRole(Roles.NullCheck)]
    public sealed class NullAttribute : ContractBase
    {
        /// <summary>
        /// Initializes a new instance of <b>Argument.Is.Null</b> class.
        /// </summary>
        /// <param name="argumentName">The name of the argument to apply contract to.</param>
        /// <exception cref="ArgumentNullException"><i>argumentName</i> is <b>null</b>.</exception>
        public NullAttribute(string argumentName)
            : base(argumentName)
        {
        }

        /// <summary>
        /// Performs validation on the argument.
        /// </summary>
        /// <param name="argument">The argument that should be validated.</param>
        /// <returns><b>true</b> if <i>argument</i> is validated, otherwise <b>false</b>.</returns>
        protected override bool ValidateArgument(object argument)
        {
            return argument == null;
        }
    }
}
